import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'

Vue.use(Router)

// 通用
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  }
]

// 管理员权限
export const adminRoutes = [
  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/user/index'),
        name: 'user',
        meta: { title: '健康档案管理', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/monitor',
    component: Layout,
    redirect: '/monitor/physical',
    meta: { title: '健康监测管理', icon: 'component'},
    children: [
      {
        component: () => import('@/views/physical/index'),
        path: 'physical',
        meta: { title: '身体指标', icon: 'component', affix: true }
      },
      {
        component: () => import('@/views/pharmacy/index'),
        path: 'pharmacy',
        meta: { title: '用药记录', icon: 'component', affix: true }
      },
      {
        component: () => import('@/views/medical/index'),
        path: 'medical',
        meta: { title: '就诊记录', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/medical/',
    component: Layout,
    redirect: '/medical/list',
    children: [
      {
        path: 'list',

      }
    ]
  },
  {
    path: '/assess/',
    component: Layout,
    redirect: '/assess/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/assess/index'),
        name: 'assess',
        meta: { title: '健康评估管理', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/meddle/',
    component: Layout,
    redirect: '/meddle/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/meddle/index'),
        name: 'meddle',
        meta: { title: '健康干预管理', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/chat/',
    component: Layout,
    redirect: '/chat/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/chat/index'),
        name: 'chat',
        meta: { title: '医患互动交流', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/education/',
    component: Layout,
    redirect: '/education/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/education/index'),
        name: 'education',
        meta: { title: '健康教育管理', icon: 'component', affix: true }
      }
    ]
  }
]

// 普通用户权限
export const staffRoutes = [
  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/user/mine'),
        name: 'user',
        meta: { title: '健康档案管理', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/monitor',
    component: Layout,
    redirect: '/monitor/physical',
    meta: { title: '健康监测管理', icon: 'component'},
    children: [
      {
        component: () => import('@/views/physical/mine'),
        path: 'physical',
        meta: { title: '身体指标', icon: 'component', affix: true }
      },
      {
        component: () => import('@/views/pharmacy/mine'),
        path: 'pharmacy',
        meta: { title: '用药记录', icon: 'component', affix: true }
      },
      {
        component: () => import('@/views/medical/mine'),
        path: 'medical',
        meta: { title: '就诊记录', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/assess/',
    component: Layout,
    redirect: '/assess/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/assess/mine'),
        name: 'assess',
        meta: { title: '健康评估管理', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/meddle/',
    component: Layout,
    redirect: '/meddle/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/meddle/mine'),
        name: 'meddle',
        meta: { title: '健康干预管理', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/chat/',
    component: Layout,
    redirect: '/chat/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/chat/index'),
        name: 'chat',
        meta: { title: '医患互动交流', icon: 'component', affix: true }
      }
    ]
  },
  {
    path: '/education/',
    component: Layout,
    redirect: '/education/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/education/mine'),
        name: 'education',
        meta: { title: '健康教育管理', icon: 'component', affix: true }
      }
    ]
  }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router;
